﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.ExpressionEvaluation
{
    /// <summary>
    /// This class provides the checking of operators like + or - and checking for one or two parameter functions 
    /// like sin, cos or atan.
    /// </summary>
    [Serializable]
    public static class OperatorInformation
    {
        /// <summary>
        /// Determines whether the specified value is a +, -, *, / or % operator.
        /// </summary>
        /// <param name="value">The string to check.</param>
        /// <returns>
        /// True if the specified value is operator otherwise, false.
        /// </returns>
        public static bool IsOperator(String value)
        {
            if (value == (string) null)
            {
                throw new ArgumentNullException("value");
            }

            return (value.Equals("+") || value.Equals("-") || value.Equals("*") || value.Equals("/")
                    || value.Equals("%"));
        }

        /// <summary>
        /// Determines whether the specified string is a one parameter function. It supports: sin, cos, tan, 
        /// sinh, cosh, tanh, asin, acos, atan, ln, log, sqrt, exp, floor, ceiling and truncate.
        /// </summary>
        /// <param name="value">The string to check.</param>
        /// <returns>
        /// True if the specified string represents a one parameter function otherwise, false.
        /// </returns>
        public static bool IsOneParameterFunction(String value)
        {
            if (value == (string) null)
            {
                throw new ArgumentNullException("value");
            }

            return (value.Equals("sin") || value.Equals("cos") || value.Equals("tan")
                    || value.Equals("sinh") || value.Equals("cosh") || value.Equals("tanh")
                    || value.Equals("asin") || value.Equals("acos") || value.Equals("atan")
                    || value.Equals("ln") || value.Equals("log") || value.Equals("sqrt")
                    || value.Equals("exp") || value.Equals("floor") || value.Equals("ceiling")
                    || value.Equals("truncate"));
        }

        /// <summary>
        /// Determines whether the specified string is a two parameter function. It supports: pow, atan2.
        /// </summary>
        /// <param name="value">The string to check.</param>
        /// <returns>
        /// True if the specified string represents a two parameter function otherwise, false.
        /// </returns>
        public static bool IsTwoParameterFunction(String value)
        {
            if (value == (string) null)
            {
                throw new ArgumentNullException("value");
            }

            return (value.Equals("pow") || value.Equals("atan2"));
        }

        /// <summary>
        /// Determines whether the specified string represents a number.
        /// </summary>
        /// <param name="value">The string to check.</param>
        /// <returns>
        /// True if the specified value is number otherwise, false.
        /// </returns>
        public static bool IsNumber(String value)
        {
            double result;

            return Double.TryParse(value, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out result);
        }
    }
}